//
//  MADareResultView.m
//  MateAdv
//
//  Created by 茶 on 2023/9/14.
//

#import "MADareResultView.h"

@interface MADareResultView ()

@property (nonatomic, strong) UILabel *contentLabel;

@end

@implementation MADareResultView

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self initInterface];
    }
    return self;
}

- (void)initInterface {
    self.backgroundColor = MAColor(@"#FF0071");
    
    UILabel *label = [UILabel new];
    label.font = MAFontScaleSemibold(25);
    label.textAlignment = NSTextAlignmentCenter;
    label.textColor = UIColor.whiteColor;
    label.numberOfLines = 8;
    label.adjustsFontSizeToFitWidth = YES;
    [self addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.ma_offset(86);
        make.right.ma_offset(-86);
        make.centerX.mas_equalTo(0);
        make.centerY.ma_offset(-100);
    }];
    _contentLabel = label;
    
    UIImageView *upView = [UIImageView initWithName:@"Dare_Up_Dot"];
    [self addSubview:upView];
    [upView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.ma_offset(47);
        make.bottom.mas_equalTo(label.mas_top).ma_offset(-4);
    }];
    
    UIImageView *downView = [UIImageView initWithName:@"Dare_Down_Dot"];
    [self addSubview:downView];
    [downView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.ma_offset(-47);
        make.top.mas_equalTo(label.mas_bottom).ma_offset(4);
    }];
    
    UIButton *closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    closeBtn.layer.cornerRadius = MARatioWidth(24);
    closeBtn.layer.masksToBounds = YES;
    [closeBtn.titleLabel setFont:MAFontScaleMedium(16)];
    [closeBtn setTitleColor:MAColor(@"#FF0071") forState:UIControlStateNormal];
    [closeBtn setBackgroundColor:UIColor.whiteColor];
    [closeBtn setTitle:@"下一个挑战" forState:UIControlStateNormal];
    [closeBtn addTarget:self action:@selector(closeEvent) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:closeBtn];
    [closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(label.mas_bottom).ma_offset(106);
        make.centerX.mas_equalTo(0);
        make.width.ma_offset(280);
        make.height.ma_offset(48);
    }];
}

- (void)closeEvent {
    MABlock(self.closeBlock);
}

- (void)setRule:(NSString *)rule {
    NSMutableParagraphStyle *style = [NSMutableParagraphStyle new];
    style.lineSpacing  = MARatioWidth(17);
    
    NSString *string = [rule stringByReplacingOccurrencesOfString:@"<name1>" withString:_fName];
    string = [string stringByReplacingOccurrencesOfString:@"<name2>" withString:_mName];
    
    NSMutableDictionary *attributes  = [NSMutableDictionary dictionary];
    [attributes setObject:style forKey:NSParagraphStyleAttributeName];
    _contentLabel.attributedText = [[NSAttributedString alloc] initWithString:string attributes:attributes];
    
}
@end
